package com.kws.commercial.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kws.commercial.dao.CommercialEquipmentLedger;
import com.kws.commercial.dao.Info.ExportEquipmentLedgerInfo;
import com.kws.commercial.dao.Info.QueryEquipmentLedgerInfo;
import com.kws.commercial.mapper.CommercialEquipmentLedgerMapper;
import com.kws.commercial.service.CommercialEquipmentLedgerService;
import com.kws.common.core.enums.ModelOpType;
import com.kws.common.core.sys.Ksys;
import com.kws.common.core.utils.KConstants;
import com.kws.common.security.utils.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <b>CommercialEquipmentLedgerServiceImpl</b>
 *
 * @description: CommercialEquipmentLedgerServiceImpl <br>
 * @date: 2024/10/30 11:38 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Service
public class CommercialEquipmentLedgerServiceImpl extends ServiceImpl<CommercialEquipmentLedgerMapper, CommercialEquipmentLedger> implements CommercialEquipmentLedgerService {
    private static final Logger logger = LoggerFactory.getLogger(CommercialEquipmentLedgerServiceImpl.class);

    @Override
    public PageInfo<QueryEquipmentLedgerInfo> queryEquipmentLedgerPage(Integer pageNum, Integer pageSize, String deviceNo, String schemeName) {
        PageHelper.startPage(pageNum,pageSize);
        Long companyId = SecurityUtils.getCompanyId();
        List<QueryEquipmentLedgerInfo> equipmentLedgerList = baseMapper.queryEquipmentLedgerPage(deviceNo,schemeName,companyId);
        return new PageInfo<QueryEquipmentLedgerInfo>(equipmentLedgerList);
    }

    @Override
    public boolean importEquipmentLedger(List<CommercialEquipmentLedger> commercialEquipmentLedgers) {
        if (CollectionUtil.isNotEmpty(commercialEquipmentLedgers)){
            commercialEquipmentLedgers.forEach(item -> {
                Ksys.setBasicModelData(item,SecurityUtils.getStringUserId(),KConstants.DATA_ENABLE, ModelOpType.CREATE);
            });
        }
        boolean b = this.saveBatch(commercialEquipmentLedgers);
        return b;
    }

    @Override
    public QueryEquipmentLedgerInfo queryEquipmentLedgerById(Long id) {
        return baseMapper.queryEquipmentLedgerById(id);
    }

    @Override
    public List<ExportEquipmentLedgerInfo> queryEquipmentLedgerList() {
        return baseMapper.queryEquipmentLedgerList();
    }
}
